<?php
class NewsController extends CommonController {
	public function index() {
		$condition = "1=1";
		if (isset ( $_GET ['title'] ) && trim ( $_GET ['title'] ) != '') {
			$condition .= " and title like '%" . filter_trim ( $_GET ['title'] ) . "%'";
		}
		$count = M ( $this->table )->where ( $condition )->count ();
		$p = new Page ( $count );
		$list = M ( $this->table )->field ( 'id,title,category_id,create_time,update_time' )->where ( $condition )->order ( 'id desc' )->limit ( $p->firstRow . ',' . $p->listRows )->select ();
		$this->assign ( 'list', $list );
		$this->assign('page',$p->show());
		$this->display ();
	}
	public function saveBefore(){
		$category_list=M('NewsCategory')->order('sort asc')->select();
		$this->assign('category_list',$category_list);
	}
	public function updateBefore(){
		$category_list=M('NewsCategory')->order('sort asc')->select();
		$this->assign('category_list',$category_list);
	}
}